package com.msoe.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.ServiceDefTarget;

public class Server
{
	private static Server serverInstance;
	private MSOERServerAsync server;
	
	private Server()
	{
		server = (MSOERServerAsync) GWT.create(MSOERServer.class);
		ServiceDefTarget endpoint = (ServiceDefTarget) server;
		endpoint.setServiceEntryPoint(GWT.getHostPageBaseURL() + "/MSOERServer");
	}
	
	/**
	 * Creates a new instance of the server if it doesn't already exist
	 * and returns it.
	 * @return an instance of this object.
	 */
	public static Server getInstance()
	{
		if(serverInstance == null) serverInstance = new Server();
		
		return serverInstance;
	}
	
	/**
	 * Gets the server used to do RPC calls on the server side.
	 * @return The server object used to do RPC calls.
	 */
	public MSOERServerAsync getServer()
	{
		return server;
	}
}
